package atguigu.jihekuangjia;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Collections;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        List<Event> events = new ArrayList<>();
        
        events.add(new Event("event1", LocalDateTime.now().minusHours(2)));
        events.add(new Event("event2", LocalDateTime.now().minusHours(4)));
        events.add(new Event("event3", LocalDateTime.now().minusHours(1)));
        
        List<Event> sortedEvents = events.stream()
                                         .sorted(Comparator.comparing(Event::getEventTime))
                                         .collect(Collectors.toList());
        
        sortedEvents.forEach(event -> System.out.println(event.getName() + ": " + event.getEventTime()));
    }
}

class Event {
    private String name;
    private LocalDateTime eventTime;
    
    public Event(String name, LocalDateTime eventTime) {
        this.name = name;
        this.eventTime = eventTime;
    }

    public String getName() {
        return name;
    }

    public LocalDateTime getEventTime() {
        return eventTime;
    }
}